<?php
/**
 * Created by PhpStorm.
 * User: hanbin
 * Date: 17/6/2
 * Time: 下午10:37
 */

namespace App\Http\Controllers\xx;


use App\Http\Controllers\BaseController;
use App\Logic\xx\FoodLogic;
use Validator;
use Illuminate\Http\Request;

class CommentController extends BaseController
{
    public function __construct()
    {
        self::setToken(true);
        parent::__construct();
    }

    /**
     * 评论
     *
     * @param Request $request
     * @return array
     */
    public function comment(Request $request)
    {
        $params = $request->all();
        $rule = [
            'food_id' => 'required|int',
            'content' => 'required|string',
        ];
        $message = [
            'food_id.required' => '菜谱ID不能为空',
            'content.required' => '内容不能为空',
        ];
        $validator = Validator::make($params, $rule, $message);
        $errors = $validator->errors()->all();
        if (!empty($errors) && !$validator->passes()) {
            return $this->error($errors[0], 206);
        }
        return FoodLogic::comment($params, $this->userId);
    }

}